<?php

namespace app\front\controller;

use think\facade\View;
use app\front\model\ad\Ad as AdModel;
use app\front\model\info\Info as InfoModel;
use app\front\model\menu\Menu as MenuModel;
use app\front\model\keyword\Keyword as KeywordModel;

/**
 * 页面控制器
 */
class Index extends Controller
{
    /**
     * 列表
     */
    public function index()
    {
        $MenuModel = new MenuModel;
        $InfoModel = new InfoModel;
        //首页广告
        $adList = (new AdModel)->getLists(['category_id' => 1], 5);
        //获取产品展示
        $productList = $MenuModel->getMenu(3, 8);
        //获取成功案例
        $caseList = $MenuModel->getMenu(4);
        //获取新闻动态
        $newsList = $MenuModel->getMenu(2, 5);
        //获取关于我们
        $aboutUs = $InfoModel::getSingleDetail(7);
        if (mb_strlen($aboutUs['desc'], 'UTF8') > 300) {
            $aboutUs['desc'] = mb_substr($aboutUs['desc'], 0, 300, 'UTF8') . '...';
        }
        //获取关键词
        $keyList = (new KeywordModel)->getLists(10);
        $aboutHref = "/info/index?menu_id=7";
        $productHref = "/info/index?menu_id=3";
        $caseHref = "/info/index?menu_id=4";
        return View::fetch('/index',
            [
                'adList' => $adList,
                'productList' => $productList,
                'aboutUs' => $aboutUs,
                'aboutHref' => $aboutHref,
                'productHref' => $productHref,
                'caseList' => $caseList,
                'caseHref' => $caseHref,
                'newsList' => $newsList,
                'keyList' => $keyList,
            ]);
    }
}
